ostbuild: Port commit-artifacts to ostbuild executor
authorColin Walters <walters@verbum.org>
Fri, 23 Dec 2011 15:57:54 +0000 (10:57 -0500)
committerColin Walters <walters@verbum.org>
Fri, 23 Dec 2011 15:57:54 +0000 (10:57 -0500)
Makefile-ostbuild.am
src/ostbuild/ostbuild-commit-artifacts [deleted file]
src/ostbuild/pyostbuild/builtin_commit_artifacts.py [new file with mode: 0644]
src/ostbuild/pyostbuild/main.py

index 96b2e37612884b0e695fa686ee339f0f41a46103..c23cea81ba704b11efaac0e4a51bffea1596e2f7 100644 (file)
@@ -20,7 +20,6 @@ ostbuild: src/ostbuild/ostbuild.in Makefile
 bin_SCRIPTS += ostbuild 
 
 bin_SCRIPTS += \
-       src/ostbuild/ostbuild-commit-artifacts \
        src/ostbuild/ostbuild-chroot-compile-one-impl \
        src/ostbuild/ostbuild-nice-and-log-output \
        $(NULL)
@@ -32,8 +31,9 @@ pyostbuild_PYTHON =                                   \
        src/ostbuild/pyostbuild/main.py                 \
        src/ostbuild/pyostbuild/ostbuildlog.py          \
        src/ostbuild/pyostbuild/subprocess_helpers.py   \
-       src/ostbuild/pyostbuild/builtin_compile_one.py  \
        src/ostbuild/pyostbuild/builtin_autodiscover_meta.py    \
+       src/ostbuild/pyostbuild/builtin_commit_artifacts.py     \
+       src/ostbuild/pyostbuild/builtin_compile_one.py  \
        $(NULL)
 
 bin_PROGRAMS += src/ostbuild/ostbuild-user-chroot
diff --git a/src/ostbuild/ostbuild-commit-artifacts b/src/ostbuild/ostbuild-commit-artifacts
deleted file mode 100644 (file)
index 5fcb21d..0000000
+++ /dev/null
@@ -1,51 +0,0 @@
-#!/usr/bin/python
-
-# Copyright (C) 2011 Colin Walters <walters@verbum.org>
-#
-# This library is free software; you can redistribute it and/or
-# modify it under the terms of the GNU Lesser General Public
-# License as published by the Free Software Foundation; either
-# version 2 of the License, or (at your option) any later version.
-#
-# This library is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-# Lesser General Public License for more details.
-#
-# You should have received a copy of the GNU Lesser General Public
-# License along with this library; if not, write to the
-# Free Software Foundation, Inc., 59 Temple Place - Suite 330,
-# Boston, MA 02111-1307, USA.
-
-# ostbuild-compile-one-make wraps systems that implement the GNOME build API:
-# http://people.gnome.org/~walters/docs/build-api.txt
-
-import os,sys,subprocess,tempfile,re
-
-i=1
-repo=sys.argv[i]
-
-artifact_re = re.compile(r'^artifact-([^,]+),([^,]+),([^,]+),([^,]+),([^.]+)\.tar\.gz$')
-
-def call_ostree_sync(*args):
-    subprocess.check_call(['ostree', '--repo=' + repo] + list(args))
-
-for arg in sys.argv[2:]:
-    basename = os.path.basename(arg)
-    match = artifact_re.match(basename)
-    if match is None:
-        print "Invalid artifact name: %s" % (arg, )
-        sys.exit(1)
-    buildroot = match.group(1)
-    buildroot_version = match.group(2)
-    name = match.group(3)
-    branch = match.group(4)
-    version = match.group(5)
-    
-    branch_name = 'artifacts/%s/%s/%s' % (buildroot, name, branch)
-
-    call_ostree_sync('commit', '-b', branch_name, '-s', 'Build ' + version,
-                     '--add-metadata-string=ostree-buildroot-version=' + buildroot_version,
-                     '--add-metadata-string=ostree-artifact-version=' + version,
-                     '--skip-if-unchanged', '--tar-autocreate-parents', '--tree=tar=' + arg)
-                     
diff --git a/src/ostbuild/pyostbuild/builtin_commit_artifacts.py b/src/ostbuild/pyostbuild/builtin_commit_artifacts.py
new file mode 100644 (file)
index 0000000..af78e71
--- /dev/null
@@ -0,0 +1,65 @@
+#!/usr/bin/python
+
+# Copyright (C) 2011 Colin Walters <walters@verbum.org>
+#
+# This library is free software; you can redistribute it and/or
+# modify it under the terms of the GNU Lesser General Public
+# License as published by the Free Software Foundation; either
+# version 2 of the License, or (at your option) any later version.
+#
+# This library is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+# Lesser General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public
+# License along with this library; if not, write to the
+# Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+# Boston, MA 02111-1307, USA.
+
+# ostbuild-compile-one-make wraps systems that implement the GNOME build API:
+# http://people.gnome.org/~walters/docs/build-api.txt
+
+import os,sys,subprocess,tempfile,re
+import argparse
+
+from . import builtins
+from .ostbuildlog import log, fatal
+from .subprocess_helpers import run_sync
+
+class OstbuildCommitArtifacts(builtins.Builtin):
+    name = "commit-artifacts"
+    short_description = "Commit artifacts to their corresponding repository branches"
+
+    def execute(self, argv):
+        artifact_re = re.compile(r'^artifact-([^,]+),([^,]+),([^,]+),([^,]+),([^.]+)\.tar\.gz$')
+
+        parser = argparse.ArgumentParser(self.short_description)
+        parser.add_argument('--repo')
+        parser.add_argument('artifacts', nargs='+')
+
+        args = parser.parse_args(argv)
+
+        if args.repo is None:
+            fatal("--repo must be specified")
+
+        for arg in args.artifacts:
+            basename = os.path.basename(arg)
+            match = artifact_re.match(basename)
+            if match is None:
+                fatal("Invalid artifact name: %s" % (arg, ))
+            buildroot = match.group(1)
+            buildroot_version = match.group(2)
+            name = match.group(3)
+            branch = match.group(4)
+            version = match.group(5)
+    
+            branch_name = 'artifacts/%s/%s/%s' % (buildroot, name, branch)
+
+            run_sync(['ostree', '--repo=' + args.repo,
+                      'commit', '-b', branch_name, '-s', 'Build ' + version,
+                     '--add-metadata-string=ostree-buildroot-version=' + buildroot_version,
+                     '--add-metadata-string=ostree-artifact-version=' + version,
+                     '--skip-if-unchanged', '--tar-autocreate-parents', '--tree=tar=' + arg])
+                     
+builtins.register(OstbuildCommitArtifacts)
index 5cd5587e5434a66475df7f79c7c2dc4f7b387398..84f8e11e516f83d59647795b2d51faf696bd972f 100755 (executable)
@@ -22,8 +22,9 @@ import sys
 import argparse
 
 from . import builtins
-from . import builtin_compile_one
 from . import builtin_autodiscover_meta
+from . import builtin_commit_artifacts
+from . import builtin_compile_one
 
 def usage(ecode):
     print "Builtins:"